﻿#pragma once
#include "common.h"
#include "Pool.h"
#include "radixMap.h"

// 饿汉模式
class pageCache {
public:
	static pageCache* getPageCache() {
		return &_pInit;
	}

	// centralCache申请k页span
	span* fetchOfPage(size_t k);

	// 获取span的起始地址
	span* getSpanOfId(void* obj);

	// 接收从centralCache返回的span
	void releasePageCache(span* backSpan);
private:
	pageCache(){}

	pageCache(const pageCache& p) = delete;
	void operator=(const pageCache& p) = delete;

	static pageCache _pInit;

private:
	spanList _pageSpanList[MAX_PAGE];

	//std::unordered_map<PAGE_T, span*> _idMap;	// id和span地址映射
	radixMap _idMap;
	Pool<span> _pool;
public:
	std::mutex _pageMutex;
};